# backend/database/session.py

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base
import os
# 获取当前文件目录的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建数据库文件的绝对路径
DATABASE_PATH = os.path.join(current_dir, "..", "followup.db")
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DATABASE_PATH}"

# # 使用 SQLite 数据库
# SQLALCHEMY_DATABASE_URL = "sqlite:///./followup.db"  # 统一为 followup.db

# connect_args 仅适用于 SQLite，其他数据库不用加
engine = create_engine(
    SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)

# 创建本地会话类
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

# 创建模型基类
Base = declarative_base()
